package com.briup.web.servlet;

import java.io.IOException;
import java.math.BigDecimal;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.SqlSession;

import com.briup.common.bean.TblArticle;
import com.briup.common.util.MyBatisSqlSessionFactory;
import com.briup.service.impl.TblArticleServiceImpl;

/**
 * Servlet implementation class articlePublisur_Servlet
 */
@WebServlet("/jsp/manager/articlePublisur_Servlet")
public class articlePublisur_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public articlePublisur_Servlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String title = request.getParameter("article.title") ;
		String author = request.getParameter("article.author") ;
		String content = request.getParameter("article.content") ;
		String category_id = request.getParameter("article.category.id") ;
		TblArticle article = new TblArticle() ;
		article.setTitle(title);
		article.setAuthor(author);
		article.setContent(content);
		article.setCategory_id(category_id);
		article.setClicktimes(0);
//		System.out.println(article);//**********************************
		SqlSession openSession = MyBatisSqlSessionFactory.openSession() ;
		try {
			TblArticleServiceImpl tblArticleServiceImpl = new TblArticleServiceImpl() ;
			int i = tblArticleServiceImpl.insertArticleByArticle(openSession, article) ;
			if (i == 1) {
				openSession.commit();
			}else {
				openSession.rollback();
			}
		} catch (Exception e) {
			openSession.rollback();
			System.out.println(e.getCause().toString());
			e.printStackTrace();
		
		}finally {
			openSession.close();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
